<?php
/**
 * Created by PhpStorm.
 * User: DD
 * Date: 2016/7/24
 * Time: 13:25
 */

namespace app\services\controller;


use app\common\util\Placeholder;
use app\common\util\QRCodeUtil;

class Img
{
    public function qrcode()
    {
        $v = I('get.v', '', 'trim');
        if (!empty($v)) {
            QRCodeUtil::png($v);
        }
    }

    public function placeholder()
    {
        $width = isset($_GET['w']) ? trim($_GET['w']) : null;
        $height = isset($_GET['h']) ? trim($_GET['h']) : null;
        $backgroundColor = isset($_GET['bgColor']) ? strtolower(trim($_GET['bgColor'])) : null;
        $textColor = isset($_GET['textColor']) ? strtolower(trim($_GET['textColor'])) : null;
        try {
            $placeholder = new Placeholder();
            $placeholder->setWidth($width);
            $placeholder->setHeight($height);
            if ($backgroundColor) $placeholder->setBackgroundColor($backgroundColor);
            if ($textColor) $placeholder->setTextColor($textColor);
            $placeholder->render();
        } catch (\Exception $e) {
            die($e->getMessage());
        }

    }
}